package com.hhly.rabbitmq.simple;

import java.io.IOException;

import com.hhly.rabbitmq.RabbitMQUtil;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Consumer;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.Envelope;

public class Recv {

	public static void main(String[] args) throws Exception {
		receive();
		System.out.println(Thread.currentThread().getName());
	}
	
	public static void  receive() throws Exception {
		Channel channel = RabbitMQUtil.getChannel();
		channel.queueDeclare(Send.QUEUE_NAME, false, false, false, null);
		Consumer consumer = new DefaultConsumer(channel) {
			@Override
			public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,
					byte[] body) throws IOException {
				String message = new String(body, "UTF-8");
				System.out.println(" [x] Received '" + message + "'");
			}
		};
		channel.basicConsume(Send.QUEUE_NAME,true,consumer);
		/*GetResponse response = channel.basicGet(Send.QUEUE_NAME, true);
		System.out.println(new String(response.getBody(),"UTF-8"));*/
	}
}
